package com.zxn.test.ui.home

import android.content.DialogInterface
import android.os.Bundle
import android.view.View
import com.zxn.mvvm.view.BaseDialogFragment
import com.zxn.test.R
import com.zxn.test.databinding.FragmentDrinkNoticeDialogBinding

private const val ARG_PARAM1 = "param1"
private const val ARG_URL = "url"
private const val ARG_NAME = "name"
private const val ARG_TIME = "time"

/**
 *  Created by zxn on 2021/10/22.
 */
class DrinkNoticeDialog : BaseDialogFragment() {

    private var mType = 0
    private var url: String? = null
    private var name: String? = null
    private var time: String? = null

    private val mBinding by lazy {
        FragmentDrinkNoticeDialogBinding.inflate(layoutInflater)
    }

    override fun onCreateRootView(): View = mBinding.root

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        arguments?.let {
            mType = it.getInt(ARG_PARAM1)
            url = it.getString(ARG_URL)
            name = it.getString(ARG_NAME)
            time = it.getString(ARG_TIME)
        }

        //isCancelable = mType == 2
    }

    override fun onInitView() {
        when (mType) {

            0 -> mBinding.ivNotice.setImageResource(R.mipmap.bg_first_glass)

            1 -> mBinding.ivNotice.setImageResource(R.mipmap.bg_first_glass)

            2 -> mBinding.ivNotice.setImageResource(R.mipmap.bg_first_glass)

            3 -> mBinding.ivNotice.setImageResource(R.mipmap.bg_first_glass)

        }

        mBinding.ivNotice.setOnClickListener {
            dismiss()
//            when (mType) {
//                1 -> DrinkCompleteDialog.newInstance(1).show(mContext.supportFragmentManager)
//
//                /*2 -> url?.let {
//                    TravelCardDgFrag.newInstance(it).show(mContext.supportFragmentManager)
//                }*/
//            }
        }
    }

    override fun onDismiss(dialog: DialogInterface) {
        super.onDismiss(dialog)
//        if (mType == 2)
//            url?.let {
//                TravelCardDgFrag.newInstance(it,name,time).show(mContext.supportFragmentManager)
//            }
    }

    companion object {

        /**
         * 0:第一个杯水,
         * 1:旅行触发提示,
         * 2:旅行回归的提示,
         * 3:旅行中无法切换鱼宠道具背景等提示.
         */
        @JvmStatic
        fun newInstance(type: Int = 0, url: String? = null, name: String? = null, time: String? = null) =
            DrinkNoticeDialog().apply {
                arguments = Bundle().apply {
                    putInt(ARG_PARAM1, type)
                    putString(ARG_URL, url)
                    putString(ARG_NAME, name)
                    putString(ARG_TIME, time)
                }
            }
    }

    /**
     * 判断当前的弹框是否可见.
     */
    fun isShowing(): Boolean = if (dialog == null) false else dialog!!.isShowing
}